
data {
  int<lower=0> N;         // number of data points
  int<lower=0> N_municipalities;         // number of data points
  int<lower=0> NbDeath[N];
  int<lower=0> Population[N];
  int<lower=0> Municipality_code[N];
  int<lower=0> covid[N]; // standard error of effect estimates
  real<lower=0> lambda;
}
parameters {
  real<upper=0> log_hc[N_municipalities];
  real<lower=0, upper=1> hcp[N_municipalities];
  real mu;
  real<lower=0> sigma;
}
  transformed parameters {
    real hc[N_municipalities];
    hc = exp(log_hc);
  }
model {
  real lambda_eff[N];
  
  mu ~ normal(-5, 5);
  sigma ~ normal(1, 20);
  
  log_hc ~ normal(mu, sigma);
  hcp ~ exponential(lambda);

  for (i in 1:N) {
    lambda_eff[i] = Population[i]*(hc[Municipality_code[i]] + covid[i]*hcp[Municipality_code[i]]);
  }

  NbDeath ~ poisson(lambda_eff);
}
